package com.homework.ch04;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;

/**
 * @author yang
 * @date 2024-03-26
 */
public class Test {
    public static void main(String[] args) throws Exception{
        Class<Student> studentClass = Student.class;
        Constructor<Student> constructor = studentClass.getConstructor(String.class, Double.class);
        Student student = constructor.newInstance("张三", 100.0);
        if (student instanceof Student){
            Method method = studentClass.getDeclaredMethod("study", String.class, Double.class);
            //对象方法是私有，所以要设置其可访问
            method.setAccessible(true);
            int invoke = (int) method.invoke(student, "教室", 5.0);
            System.out.println("学习经验+"+invoke);
        }
    }
}
